<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Cache;

/**
 * Class Places
 *
 * @package App\Model
 * @mixin \Eloquent
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places query()
 * @property int $id 主键id
 * @property string $name 地区名称
 * @property int $pid 上级id
 * @property string $short_name 简称
 * @property int $level 层级
 * @property string $city_code 城市代码
 * @property string $zip_code 邮政编码
 * @property string $merge_name 完整地址
 * @property float $lng 经度
 * @property float $lat 纬度
 * @property string $pinyin 拼音
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereCityCode($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereLat($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereLevel($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereLng($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereMergeName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places wherePid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places wherePinyin($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereShortName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Model\Places whereZipCode($value)
 */
class Places extends Model
{
    protected $table = 'places';

    public static function getPlacesName($id)
    {
        $places = Cache::remember('places', 1440, function () use ($id) {
            return (new Places)->pluck('name', 'id');
        });
        return isset($places[$id])?$places[$id]:'';
    }

}
